/* START DHTML BUILDING BLOCKS */
var SuggestTimer;
var ZZLOGON_LANG;
var Resizable;

var oMPosX;
var oWidth;
var oMinW = 100;
var oMaxW = 500;
var DELAY_SECOND = 800;
var DELAY_CTRL_KEY = 1000;
var ZZAutocomplete_DELAY = 500;

var oPreElement = "";

var ZDEF_KEY_TIMES = 0;
var ZDEF_DIR_U = 0;
var ZDEF_DIR_D = 1;
var ZDEF_DIR_L = 2;
var ZDEF_DIR_R = 3;
var ZDEF_DIR_PGUP = 4;
var ZDEF_DIR_PGDN = 5;
var ZDEF_DIR_HOME = 6;
var ZDEF_DIR_END = 7;

var ALIGN_AUTO = 0;
var ALIGN_LEFT = 1;
var ALIGN_CENTER = 2;
var ALIGN_RIGHT = 3;

var COL_HEAD_NONE = 0;
var COL_HEAD_EDGE = 1;
var COL_HEAD_OVER = 2;
var COL_HEAD_SIZE = 3;
var COL_HEAD_DOWN = 4;
var COL_HEAD_MOVE = 5;

var ZDEF_ESCAPE = 27;
var ZDEF_LEFT = 37;
var ZDEF_RIGHT = 39;
var ZDEF_UP = 38;
var ZDEF_DOWN = 40;
var ZDEF_TAB = 9;
var ZDEF_ENTER = 13;
var ZDEF_SPACE = 32;
var ZDEF_SHIFT = 16;
var ZDEF_CTRL = 17;
var ZDEF_ALT = 18;
var ZDEF_HOME = 36;
var ZDEF_END = 35;
var ZDEF_PGUP = 33;
var ZDEF_PGDN = 34;

var oSuggest = null;
var ZZUKB_SETTING = new Array();
var ZZUKB_OBJECT = new Array();
var ZZCTRL_KEY_PRESS = false;
var oCTRL_KEY_PRESS;

function FindElementPosX(obj)
 {
    curleft = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curleft += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
    {
        curleft += obj.x;
    }
    return curleft;
}

function FindElementPosY(obj)
 {
    curtop = 0;
    if (obj.offsetParent)
    {
        while (obj.offsetParent)
        {
            curtop += obj.offsetTop;
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
    {
        curtop += obj.y;
    }
    return curtop;
}

function getLeftPos(_el)
 {
    var x = 0;
    for (var el = _el; el; el = el.offsetParent)
    {
        x += el.offsetLeft;
    }
    return x;
}

function IsWithinNode(oEvent, i, c, t, obj)
 {
    answer = false;
    te = oEvent;
    while (te && !answer)
    {
        if ((te.id && (te.id == i)) || (te.className && (te.className == i + "Class")) || (!t && c && te.className && (te.className == c)) || (!t && c && te.className && (te.className.indexOf(c) != -1)) || (t && te.tagName && (te.tagName.toLowerCase() == t)) || (obj && (te == obj)))
        {
            answer = te;
        }

        else
        {
            te = te.parentNode;
        }
    }
    return te;
}

function IsWithinWxf(oEvent)
 {
    var answer = false;
    var te = oEvent;
    while (te && !answer)
    {
        if (te)
        {
            if (te.getAttribute)
            {
                var datatype = te.getAttribute("datatype");
                if (datatype == 't')
                {
                    answer = true;
                }
                else
                {
                    te = te.parentNode;
                }
            }
            else
            {
                te = te.parentNode;
            }
        }
        else
        {
            te = te.parentNode;
        }
    }
    return te;
}

function XEvent(event)
 {
    var _Event = (event ? event: window.event);
    if (document.layers)
    {
        this.altKey = ((_Event.modifiers & Event.ALT_MASK) > 0);
        this.ctrlKey = ((_Event.modifiers & Event.CONTROL_MASK) > 0);
        this.shiftKey = ((_Event.modifiers & Event.SHIFT_MASK) > 0);
    }
    else
    {
        this.altKey = _Event.altKey;
        this.ctrlKey = _Event.ctrlKey;
        this.shiftKey = false;
    }

    this.keyCode = _Event["keyCode"];
    if (this.keyCode == 0 && _Event["which"] != 0)
    {
        this.keyCode = _Event["which"];
    }

    this.Type = _Event["type"];
    if (this.keyCode == 190)
    {
        this.iChar = '>';
    } else if (this.keyCode == 188)
    {
        this.iChar = '<';
    } else {
        this.iChar = String.fromCharCode(this.keyCode);
    }

    this.XElement = _Event.srcElement ? _Event.srcElement: (_Event.target ? _Event.target: _Event.currentTarget);
    this.XEvent = _Event;

    this.FreezeEvent = function()
    {
        if (_Event.preventDefault)
        {
            _Event.preventDefault();
        }

        _Event.cancelBubble = true;
        _Event.returnValue = false;

        if (_Event.stopPropagation)
        {
            _Event.stopPropagation();
            _Event.preventDefault();
        }
        return false;
    };

    this.FireEvent = function(nkc)
    {
        this.FreezeEvent();

        if (window.event)
        {
            _Event.keyCode = nkc;
        }
        else
        {
            var newEvent = document.createEvent("KeyEvents");
            newEvent.initKeyEvent("keypress", true, true, document.defaultView, _Event.ctrlKey, _Event.altKey, _Event.shiftKey, _Event.metaKey, 0, nkc);
            _Event.preventDefault();
            _Event.target.dispatchEvent(newEvent);
        }
    };

    this.NFocus = function()
    {
        eL = this.XElement;
        cType = _Event["type"];
        this.FreezeEvent();
        if (eL && cType == "keydown")
        {
            var i = 0;
            var bAfter = false;
            var oFl;
            var bValid = false;
            while (i < eL.form.length)
            {
                bValid = false;
                if (eL.form[i] == eL)
                {
                    bAfter = true;
                }
                var eL2 = eL.form[i + 1];
                if (eL2)
                {
                    var eType = eL2.type.toUpperCase();
                    if ((eType == "TEXT" || eType == "TEXTAREA" || eType == "SELECT-ONE") && (!eL2.readOnly) && (eL2.tabIndex != 0) && (!eL2.disabled))
                    {
                        if (!oFl)
                        {
                            oFl = eL2;
                        }
                        bValid = true;
                    }
                }
                if (bAfter && bValid)
                {
                    eL2.focus();
                    if (eType == "TEXT")
                    {
                        eL2.select();
                    }
                    return;
                }
                i++;
            }
            if (i == eL.form.length && oFl)
            {
                if (oFl == eL)
                {
                    //	oFl.onblur();
                    }
                oFl.focus();
            }
        }
        return;
    };
}

function AddZero(vNumber)
 {
    return ((vNumber < 10) ? "0": "") + vNumber
}

function _HideTips(cDiv)
 {
    var oTipDiv = document.getElementById(cDiv);
    if (oTipDiv)
    {
        oTipDiv.style.display = 'none';
    }

    oTipDiv = document.getElementById("messagelayer");
    if (oTipDiv)
    {
        oTipDiv.style.display = 'none';
    }

}

function FormatDate(vDate, vFormat)
 {
 	  if (vFormat=="")
 	  {
 	  	vFormat="yyyy-MM-dd";
 	  }
 	  if (vDate==0)
 	  {
 	  	return "";
 	  }
    var vDay = AddZero(vDate.getDate());
    var vMonth = AddZero(vDate.getMonth() + 1);
    var vYearLong = AddZero(vDate.getFullYear());
    var vYearShort = AddZero(vDate.getFullYear().toString().substring(3, 4));
    var vYear = (vFormat.indexOf("yyyy") > -1 ? vYearLong: vYearShort);
    var vHour = AddZero(vDate.getHours());
    var vMinute = AddZero(vDate.getMinutes());
    var vSecond = AddZero(vDate.getSeconds());
    var vDateString = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear);
    vDateString = vDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond);
    return vDateString;
}

function ToClipboard(meintext)
 {
    if (window.clipboardData)
    {
        window.clipboardData.setData("Text", meintext);
    }
}


function Column(cName, cType, cEditable, cWidth)
 {
    this.Name = cName;
    this.DataType = cType;
    this.Readonly = true;
    this.Width = cWidth;

    if (cEditable == "y")
    {
        this.Readonly = false;
    }
}

function XAutoSuggest_CallBack(responseText, responseXML)
{
    try
    {
        eval(responseText);
        setSuggestData();
        var Content = getSuggestContent();
        if (Content)
        {
            ModiWINSuggestContent(Content);
            DispWINSuggest();
        }
        else
        {
            HideWINSuggest();
        }
    }
    catch(ex)
    {
        alert(ex.message);
    }
}

function XAutoSuggest_Error(status, statusText, responseText)
 {
    window.status = status;
}

function XAutoSuggest(textname)
 {
    if (ZZAutocomplete == false)
    {
    	return;
    }
    var eL = document.getElementById(textname);
    oSuggest = new WINSuggest();
    oSuggest.TextBox = eL;

    oSuggest.ActiveBox = true;

    var thisData = "&ZZLOGON_LANG=" + URLEncode(ZZLOGON_LANG) + "&ACTIVE_CODE=" + eL.name + "&UGET_CODE=" + URLEncode(eL.getAttribute("uget_code"));

    thisData = thisData + "&d={lnk_dbName}";
    thisData = thisData + "&t={ZZLiveBlock}";

    oAjaxSuggest = new AsyncRequest();
    oAjaxSuggest.OnComplete = XAutoSuggest_CallBack;
    oAjaxSuggest.OnError = XAutoSuggest_Error;
    oAjaxSuggest.setPage("../UPl/AsyncSuggest.ashx");
    oAjaxSuggest.DoCallBack(thisData, "");
}


function HideWINSuggest()
 {
    if (SuggestTimer)
    {
        window.clearTimeout(SuggestTimer);
    }

    if (oSuggest)
    {
        oSuggest.AutoSuggestContent.style.display = "none";
        oSuggest.AutoSuggestContent.style.visibility = "hidden";
        oSuggest = null;
    }

    oSuggest = null;
}

function DispWINSuggest()
 {
    if (oSuggest)
    {
        if (!oSuggest.AutoSuggestContent.style.display || (oSuggest.AutoSuggestContent.style.display == "none"))
        {
            x = FindElementPosX(oSuggest.TextBox);
            y = FindElementPosY(oSuggest.TextBox) + oSuggest.TextBox.offsetHeight;

            oSuggest.AutoSuggestContent.style.left = x;
            oSuggest.AutoSuggestContent.style.top = y;
            oSuggest.AutoSuggestContent.style.display = "block";
            oSuggest.AutoSuggestContent.style.visibility = "visible";
            oSuggest.AutoSuggestContent.style.zIndex = 2001;
        }
    }
}

function setSuggestData()
 {
    if (oSuggest)
    {
        orgUserInput = oSuggest.TextBox.value;
        userInput = orgUserInput;
    }
}

function Now_Time()
 {
    var temp = new Date();
    return temp.valueOf();
}

function ModiWINSuggestContent(Content)
 {
    if (oSuggest)
    {
        if (oSuggest.AutoSuggestContent)
        {
            oSuggest.AutoSuggestContent = document.getElementById("HIDE_AutoSuggestContent");
            oSuggest.AutoSuggestContent.innerHTML = '<div id="AutoSuggestResults" > ' + Content + ' </div>';
            oSuggest.MatchListDisplay = document.getElementById("AutoSuggestResults");
        }
    }
}

function getSuggestContent()
 {
    var a = null;
    if (oSuggest)
    {
        if (oSuggest.Content == '')
        {
        		if (oSuggest.MatchCollection)
        		{
	            if (oSuggest && oSuggest.MatchCollection && (oSuggest.MatchCollection.length > 0))
	            {
	                a = '<table width=100% cellspacing=0 cellpadding=0 border=0 >';
	                a += '<tr>';
	                a += '<td class="sbg">';
	                a += '<table width=100% class=wxfcell cellspacing=0 cellpadding=0 border=1 bordercolor=LightGrey>';
	                if (oSuggest.Columns)
	                {
	                    a += '<tr style="height:23px;">';
	                    a += oSuggest.Columns;
	                }
	                for (i = 0; i < oSuggest.MatchCollection.length; i++)
	                {
	                    a += '<tr class=wxfdr style="height:23px;" onmousedown="ActiveFromMouseClick();return false;" onmouseover="ActiveFromMouseOver(' + i + ');">';
	                    var oDataArray = oSuggest.MatchCollection[i].DataArray;
	                    for (j = 0; j < oDataArray.length; j++)
	                    {
	                        a += '<td valign=center class="{NDX_' + i + '}" nowrap=1>';
	
	                        if (oDataArray[j] != "" && oDataArray[j] != null)
	                        {
	                            a += oDataArray[j];
	                        }
	                        else
	                        {
	                            a += "&nbsp;";
	                        }
	                    }
	                }
	                a += '</table>';
	            }
          	}
        } else {
            a = oSuggest.Content;
        }

        a = ReplaceAll(a, '{NDX_' + oSuggest.ActiveNDX + '}', 'asi');
				if (oSuggest.MatchCollection)
				{
	        for (j = 0; j < oSuggest.MatchCollection.length; j++)
	        {
	            a = ReplaceAll(a, '{NDX_' + j + '}', 'nsi');
	        }
      	}
    }
    return a;
}

function PrevSuggest()
 {

    if (oSuggest && oSuggest.MatchCollection)
    {
        if (oSuggest.ActiveNDX > 0)
        {
            ActiveSuggest(oSuggest.ActiveNDX - 1);
            ModiWINSuggestContent(getSuggestContent());
        }
    }
}

function NextSuggest()
 {
    if (oSuggest && oSuggest.MatchCollection)
    {
        if (oSuggest.ActiveNDX < oSuggest.MatchCollection.length - 1)
        {
            ActiveSuggest(oSuggest.ActiveNDX + 1);
            ModiWINSuggestContent(getSuggestContent());
        }
    }
}

function ActiveSuggest(i)
 {
    if (oSuggest)
    {
        if (oSuggest.MatchCollection)
        {
            oSuggest.ActiveNDX = i;
        }
    }
}

function getCurrentlySuggest()
 {
    crtn = null;
    if (oSuggest)
    {
        if (oSuggest.MatchCollection)
        {
            if (oSuggest.ActiveNDX == -1)
            {
                return crtn;
            } else {
                return oSuggest.ActiveNDX;
            }
        }
    }
    return crtn;
}

function ActivateCurrentMatch()
 {
    selIndex = getCurrentlySuggest();
    if (selIndex != null)
    {
        theString = oSuggest.MatchCollection[selIndex].Clean;
        oSuggest.TextBox.value = theString;
    }
    else
    {}
}

function ActiveFromMouseOver(i)
 {
    if (oSuggest)
    {
        if (oSuggest.ActiveNDX != i)
        {
            ActiveSuggest(i);
            ModiWINSuggestContent(getSuggestContent());
        }
    }
}

function ActiveFromMouseClick()
 {
    ActivateCurrentMatch();
    oSuggest.TextBox.focus();
    HideWINSuggest();
}

function MatchSuggest(cClean, value, oArray)
 {
    this.Clean = cClean;
    this.value = value;
    this.IsActive = false;
    this.DataArray = oArray;
}

function WINSuggest()
 {
    this.AutoSuggestContent = document.getElementById("HIDE_AutoSuggestContent");
    this.ActiveNDX = -1;
    this.Content = "";
    this.Columns = "";
    this.Fields = 0;
}
